package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class Tax extends AbstractData {
	private long id = -1;
	private long hotelId;
	private String shortname;
	private Double CurrencyValue;
	private CurrencyMaster currency;
	private String currencyString;
	private boolean IsOnRoomTariff;
	private boolean status;
	private boolean avaliable;
	private String description;
	private long sortOrder;

	
	public void setId(long id) {
		this.id = id;
	}

	public Tax()
	{
		status = true;
		avaliable = true;
	}
	
	public Tax(long id){
		this.id = id;
		this.status = true;
		this.avaliable = true;
	}

	@Override
	public long getId() {
		return id;
	}

	public long getHotelId() {
		return hotelId;
	}

	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public boolean isAvaliable() {
		return avaliable;
	}

	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}


	public String getShortname() {
		return shortname;
	}

	public void setShortname(String shortname) {
		this.shortname = shortname;
	}

	public Double getCurrencyValue() {
		return CurrencyValue;
	}

	public void setCurrencyValue(Double currencyValue) {
		CurrencyValue = currencyValue;
	}

	public CurrencyMaster getCurrency() {
		if (currency == null && !(currencyString == null || currencyString.isEmpty())) {
			CurrencyMaster c = new CurrencyMaster(Long.parseLong(currencyString));	
			c.LoadData();
			currency = c;
		}
		return currency;
	}

	public void setCurrency(CurrencyMaster currency) {
		this.currencyString = String.format("%d", currency.getId());
		this.currency = currency;
	}

	public boolean isIsOnRoomTariff() {
		return IsOnRoomTariff;
	}

	public void setIsOnRoomTariff(boolean isOnRoomTariff) {
		IsOnRoomTariff = isOnRoomTariff;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public void setCurrencyString(String currencyString) {
		this.currencyString = currencyString;
	}

	public long getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(long sortOrder) {
		this.sortOrder = sortOrder;
	}

	public String getCurrencyString() {
		return currencyString;
	}

	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.Tax);
		else
			item = new Entity(this.key);

		item.setProperty("HotelId", this.hotelId);
		item.setProperty("Status", this.status);
		item.setProperty("Avaliable", this.avaliable);
		item.setProperty("Shortname", this.shortname);
		item.setProperty("CurrencyValue", this.CurrencyValue);
		item.setProperty("Currency", this.currencyString);
		item.setProperty("IsOnRoomTariff", this.IsOnRoomTariff);
		item.setProperty("Description", this.description);
		item.setProperty("SortOrder", this.sortOrder);
		
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("HotelId");
		this.status = (Boolean) entity.getProperty("Status");
		this.avaliable = (Boolean) entity.getProperty("Avaliable");
		this.shortname = (String) entity.getProperty("Shortname");
		this.CurrencyValue = (Double) entity.getProperty("CurrencyValue");
		this.currencyString = (String) entity.getProperty("Currency");
		this.IsOnRoomTariff = (Boolean) entity.getProperty("IsOnRoomTariff");
		this.description = (String) entity.getProperty("Description");
		this.sortOrder = (Long) entity.getProperty("SortOrder");

		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.Tax, this.id);
			setEntity(entity);
		}
	}

}
